package com.dis.demo;

/**
 * 软谋教育Java VIP课程
 * <pre>
 *    今日内容:IOC和DI
 * </pre>
 *
 * @author gerry
 * @date 2018-07-05
 */
public class TestLock {
    static int n = 500;

    public static void secskill() {
        System.out.println(--n+"=============================");
    }

    public static void main(String[] args) {

        Runnable runnable = new Runnable() {
            public void run() {
                DistributeLock lock = null;
                try {
                    lock = new DistributeLock("127.0.0.1:2181", "test");
                    lock.lock();

                    secskill();
                    System.out.println(Thread.currentThread().getName() + "正在运行");
                } finally {
                    if (lock != null) {
                        lock.unlock();
                    }
                }
            }
        };

        for (int i = 0; i < 10; i++) {
            Thread t = new Thread(runnable);
            t.start();
        }
    }
}
